package com.jin.webvideo.videoCache.policy.operation;

import java.util.HashMap;
import java.util.Map;

public class OperationFactory {
    private static OperationFactory factory;
    private Map<String, Operation> map;
    private OperationFactory(){
        map = new HashMap<>();
    }
    public void register(Operation operation){
        map.put(operation.getSymbol(), operation);
    }
    public boolean contains(String symbol){
        return map.containsKey(symbol);
    }
    public static OperationFactory newInstance() {
       if (null == factory){
           synchronized (OperationFactory.class){
               if (null == factory){
                   factory = new OperationFactory();
                   init(factory);
               }
           }
       }
       return factory;
    }
    public Operation get(String symbol){
        return map.get(symbol);
    }
    private static void init(OperationFactory factory){
        factory.register(new EqualOperation());
        factory.register(new InOpeartion());
        factory.register(new NotEqualOperation());
    }
}
